package nl.scalasim
package actors
package traits

/**
 * Base class for all actors that participate in a ScalaSim simulation;
 * this excludes the so-called control-actors.
 *
 * All simulation actors have a descriptor which contains the immutable
 * information about the actor.  
 *
 * @author Yigal Duppen
 * @since Oct 20, 2010
 */
class SimulationActor(val descriptor: ActorDescriptor) extends ComposedActor {

  private[traits] def stored: Map[Goods, Amount] = Map()

  private[traits] def maxStorageCapacity = 0

  private[traits] def residents: Amount = Amount(0, 0)

  private[traits] def workers: Amount = Amount(0, 0)

  private var _related = Set[SimulationActor]()
  private def related: Set[SimulationActor] = _related

  private[traits] def addRelated(a: SimulationActor) = {
    _related += a
  }

  def handleGetState: PartialFunction[Any, Unit] = {
    case GetState => {
      reply(ActorState(descriptor = descriptor,
        stored = stored,
        maxCapacity = maxStorageCapacity,
        residents = residents,
        workers = workers,
        related = related))
    }
  }
  callbacks :+= handleGetState


  override def toString: String = {
    descriptor.name + "@" + System.identityHashCode(this)
  }
}